package com.itany.corejava.code07_面向对象.bms;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月07日 15:49
 */
public class LoanSavingAccount extends SavingAccount implements  Loanable{
    private double loanAmount;//贷款金额

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    /**
     * 贷款方法
     * @param money 贷款金额
     */
    @Override
    public void providerLoan(double money) {
        //因为我们没有做任何审批流程，默认直接申请成功
        // 贷款金额=原来的贷款金额+当前的贷款金额
        loanAmount+=money;
    }

    /**
     * 还款方法
     * @param money 还款金额
     * @return
     */
    @Override
    public boolean payLoan(double money) {
        if(getBalance()>=money){//余额>=还款金额，还钱，余额就会减少
            setBalance(getBalance()-money);
            loanAmount-=money;//贷款还了一部分之后，贷款的钱会变少
            return true;

        }
        return false;
    }


    /**
     * 查询当前还剩下的贷款金额
     * @return
     */
    @Override
    public double queryLoan() {
        return loanAmount;
    }
}
